const RECommon = {
  // ids
  ids: () => {
    let pattern = String.raw`^([0-9A-Za-z]*,?)*$`;
    let msg = '批量格式错误';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // enums
  enums: () => {
    let pattern = String.raw`^([0-9A-Za-z]*,?)*$`;
    let msg = '批量格式错误';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // base64
  base64: () => {
    let pattern = String.raw`^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$`;
    let msg = 'base64格式错误';
    return {
      reg: new RegExp(pattern, ''),
      msg,
    };
  },
  // 短文本
  text: (min, max, level = 3) => {
    let pattern = '';
    let msg = '异常校验';
    switch (level) {
      case 0:
        pattern = String.raw`^[A-Za-z]{` + min + ',' + max + '}$';
        msg = '支持大小写字母,' + min + '-' + max + '位';
        break;
      case 1:
        pattern = String.raw`^[A-Za-z0-9]{` + min + ',' + max + '}$';
        msg = '支持大小写字母数字,' + min + '-' + max + '位';
        break;
      case 2:
        pattern = String.raw`^[A-Za-z0-9_-]{` + min + ',' + max + '}$';
        msg = '支持大小写字母数字—_,' + min + '-' + max + '位';
        break;
      case 3:
        pattern = String.raw`^[\u4e00-\u9fa5A-Za-z0-9_-]{` + min + ',' + max + '}$';
        msg = '支持中文大小写字母数字—_,' + min + '-' + max + '位';
        break;
      case 4:
        pattern =
          String.raw`^(?!.*<[a-zA-Z]+.*[/]?>.*)[\u4e00-\u9fa5\u0021-\u007e\u00b7]{` +
          min +
          ',' +
          max +
          '}$';
        msg =
          '支持大小写字母数字以及键盘上英文特殊符号以及·(不包括空格,制表符,换行,中文符号),' +
          min +
          '-' +
          max +
          '位';
        break;
      case 5:
        pattern =
          String.raw`^(?!.*<[a-zA-Z]+.*[/]?>.*)[\u4e00-\u9fa5\u0020-\u007e\u00b7]{` +
          min +
          ',' +
          max +
          '}$';
        msg =
          '支持大小写字母数字以及键盘上英文特殊符号以及·包括空格(不包括制表符,换行,中文符号),' +
          min +
          '-' +
          max +
          '位';
        break;
      case 6:
        pattern =
          String.raw`^(?!.*<[a-zA-Z]+.*[/]?>.*)[^s][\u4e00-\u9fa5\u0020-\u007e\u00b7}]{` +
          min +
          ',' +
          max +
          '}$';
        msg =
          '支持大小写字母数字以及键盘上英文特殊符号以及·包括中间空格(不包括制表符,换行,中文符号),' +
          min +
          '-' +
          max +
          '位';
        break;
    }
    return {
      reg: pattern ? new RegExp(pattern, '') : '',
      msg,
    };
  },
};

export default RECommon;
